local ty_changan = fk.CreateSkill {
  name = "ty_changan",
  mode_skill = true,
}

Fk:loadTranslationTable{
  ["ty_changan"] = "长安",
  [":ty_changan"] = "摸牌阶段，你可以随机获得两张不同的“文和乱武”锦囊牌。",

}

local U = require "packages/utility/utility"

local ty_changan_derivecards = {
  {"time_flying", Card.Heart, 1},
  {"time_flying", Card.Diamond, 5},
  {"substituting", Card.Heart, 1},
  {"substituting", Card.Heart, 13},
  {"substituting", Card.Diamond, 12},
  {"replace_with_a_fake", Card.Spade, 11},
  {"replace_with_a_fake", Card.Spade, 13},
  {"replace_with_a_fake", Card.Club, 12},
  {"replace_with_a_fake", Card.Club, 13},
  {"wenhe_chaos", Card.Spade, 10},
  {"wenhe_chaos", Card.Club, 4}
}

ty_changan:addEffect(fk.DrawNCards, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(ty_changan.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cids = table.filter(U.prepareDeriveCards(room, ty_changan_derivecards, ty_changan.name), function (id)
        return room:getCardArea(id) == Card.Void
      end)
      if #cids == 0 then
        cids = table.filter(U.prepareDeriveCards(room, ty_changan_derivecards, ty_changan.name), function (id)
          return table.contains(room.draw_pile, id)
        end)
      end
      if #cids > 0 then
        local to_get = {}
        local id = table.random(cids)
        table.insert(to_get, id)
        for _,id2 in ipairs(cids) do
          if Fk:getCardById(id2).trueName ~= Fk:getCardById(id).trueName then
            table.insert(to_get, id2)
            break
          end
        end
        room:obtainCard(player, to_get, false, fk.ReasonJustMove, player, ty_changan.name, MarkEnum.DestructIntoDiscard)
        if player.dead then return end
      end
  end,
})

return ty_changan